﻿@{
    Layout = null;
}
@model LY.Manage.Model.Department

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>ShowAddInfo</title>
    <link href="~/plugins/layui/css/layui.css" rel="stylesheet" />
   
    <script src="~/plugins/layui/layui.js"></script>
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>
    <script src="~/Scripts/lyUtils.js"></script>

    @*<script src="~/Scripts/MyAjaxForm.js"></script>*@
    <script type="text/javascript">
      

        //function subForm() {
        //    alert("subForm--提交数据");
        //    top.layer.msg("提交数据！");
        //    $("#fmMain").submit();
        //}
        //function afterAdd(data) {
        //    //console.log("sub-after-add:" + data);
        //    ////调用父窗体中的方法
        //    //window.parent.afterAdd(data);
        //    alert("提交之后");
        //    top.layer.msg("提交之后！");
        //    var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });
        //}

    </script>


</head>
<body>
@*@using (Ajax.BeginForm("AddInfo", "DemoInfo", new { }, new AjaxOptions()
{
    HttpMethod = "post",
    OnSuccess = "afterAdd",
}, new { id = "fmMain", @class = "layui-form" }
))
    {*@
    <form class="layui-form" id="fmMain" action="/DemoInfo/AddInfo" method="post">
        <div class="layui-form-item">
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="请输入姓名" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">Email</label>
                <div class="layui-input-inline">
                    <input type="text" name="email" lay-verify="email" placeholder="请输入Email" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-inline">
                    <input type="radio" name="sex" value="男" title="男" checked="">
                    <input type="radio" name="sex" value="女" title="女">

                </div>
            </div>

        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">年龄</label>
                <div class="layui-input-inline">
                    <input type="text" name="age" lay-verify="number" autocomplete="off" placeholder="请输入年龄" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">出生日期</label>
                <div class="layui-input-inline">
                    <input type="text" name="birthday" id="birthday" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">

                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">时间选择器</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" name="time" id="time" placeholder="HH:mm:ss">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-inline">
                    @Html.DropDownList("DepName", ViewBag.DevNameList as IEnumerable<SelectListItem>)
                    @*@Html.DropDownListFor(model => model.ParentId, ViewBag.DevNameList as IEnumerable<SelectListItem>, new { @class = "form-control" })*@

                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <label class="layui-form-label">启用-默认是</label>
                    <div class="layui-input-block">
                        <input type="checkbox" checked="" name="isenable" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

     @*}*@
    

   
    <!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
    <script>

    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            layedit = layui.layedit,
            laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#birthday',

        });
        laydate.render({
            elem: '#time',
            type: 'time'

        });


        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            //title: function (value) {
            //    if (value.length < 5) {
            //        return '标题至少得5个字符啊';
            //    }
            //},
            //pass: [/(.+){6,12}$/, '密码必须6到12位'],
            //content: function (value) {
            //    layedit.sync(editIndex);
            //}
        });
        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            //  layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });


        form.on("submit(demo1)", function (data) {
        
            var index = top.layer.msg('数据提交中，请稍候', { icon: 16, time: false, shade: 0.8 });
            // 实际使用时的提交信息
            $.ajax({
                type: "POST",
                dataType: "json",
                url: "/DemoInfo/AddInfo",
                data: $('#fmMain').serialize(),// 要提交表单的ID
                success: function (res) {
                 
                    if (res.IsSuccess == true) {
                        setTimeout(function () {
                            top.layer.close(index);
                            top.layer.msg("文章添加成功！");
                            layer.closeAll("iframe");
                            //刷新父页面
                            parent.location.reload();
                        }, 500);
                    } else {
                        top.layer.msg("文章添加失败！");
                    }
                }
            });



            //$.post("/DemoInfo/AddInfo",$("#fmMain").serialize(),{
              

            //    //newsName : $(".newsName").val(),  //文章标题
            //    //abstract : $(".abstract").val(),  //文章摘要
            //    //content : layedit.getContent(editIndex).split('<audio controls="controls" style="display: none;"></audio>')[0],  //文章内容
            //    //newsImg : $(".thumbImg").attr("src"),  //缩略图
            //    //classify : '1',    //文章分类
            //    //newsStatus : $('.newsStatus select').val(),    //发布状态
            //    //newsTime : submitTime,    //发布时间
            //    //newsTop: data.filed.newsTop == "on" ? "checked" : "",    //是否置顶
            //    //name: $("name").val(),
            //    //Email: $("Email").val(),
            //    //age: $("age").val(),

            //    },function(res){
            //        top.layer.msg(res.IsSuccess);
            //        if (res.IsSuccess==true)
            //        {
            //            setTimeout(function () {
            //                top.layer.close(index);
            //                top.layer.msg("文章添加成功！");
            //                layer.closeAll("iframe");
            //                //刷新父页面
            //                parent.location.reload();
            //            }, 500);
            //        } else
            //        {
            //            top.layer.msg("文章添加失败！");
            //        }
            //    })

            return false;
        });


    });
    </script>

</body>
</html>
